const $ = el => document.querySelector(el)

const $all = el => [...document.querySelectorAll(el)]

const addZero = n => n < 10 ? '0' + n : n
 
const request = ({
  method = 'GET',
  url
}) => {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest()
    xhr.open(method, url)
    xhr.onreadystatechange = () => {
      if (xhr.readyState === 4) {
        if (xhr.status === 200) {
          const data = JSON.parse(xhr.responseText)
          resolve(data)
        } else {
          alert('请求失败:' + xhr.status)
          reject(xhr)
        }
      }
    }
    xhr.send()
  })
}

const getQuery = () => {
  const params = {}
  const search = location.search.slice(1).split('&')
  search.forEach(item => {
    const [key, val] = item.split('=')
    params[key] = val
    console.log(params)
  })
  return params
}